package com.zxy.barometer.common.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.barometer.model.Dictiontry;
import com.zxy.barometer.service.DictiontryService;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 天气工具类
 *
 * @author zxy
 */
@Component
public class WeatherConditionUtil {
    private final DictiontryService dictiontryService;

    public WeatherConditionUtil(DictiontryService dictiontryService) {
        this.dictiontryService = dictiontryService;
    }

    /**
     * 天气信息
     */
    public static Map<String, String> resultWeatherConditionMap = new HashMap<>(33);

    @PostConstruct
    public void readWeatherCondition() {
        QueryWrapper<Dictiontry> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dict_type", "WEATHERCONDITION");
        queryWrapper.eq("status", 1);
        List<Dictiontry> dictiontryList = dictiontryService.list(queryWrapper);
        dictiontryList.forEach(dictiontry -> resultWeatherConditionMap.put(dictiontry.getDictCode(), dictiontry.getName()));
    }
}
